package com.bdqn.service;

import com.bdqn.mapper.SysUserMapper;
import com.bdqn.pojo.SysUser;
import com.bdqn.util.MyBatisUtil;
import com.sun.corba.se.spi.ior.iiop.IIOPFactories;
import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;

public class SysUserServiceImpl implements SysUserService {
    //引入log4j
    private static final Logger logger = Logger.getLogger(SysUserServiceImpl.class);

    @Override
    public SysUser login(String account, String password) {
        if (account == null || password == null) {//参数错误
            System.out.println("参数错误");
            return null;
        }

        SysUser sysUser = null;//如果登录成功返回用户信息
        SqlSession sqlSession = null;
        try {

            sqlSession = MyBatisUtil.createSession();
            sysUser = sqlSession.getMapper(SysUserMapper.class).getByAcooount(account);
            if (sysUser == null) {//账号不存在
                System.out.println("账号不存在");
                return null;
            }
            if (password.equals(sysUser.getPassword())) {//密码不匹配
                System.out.println("密码不匹配");
                return null;
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.fillInStackTrace();
        } finally {
            MyBatisUtil.closeSqlSession(sqlSession);
        }

        return sysUser;
    }
}
